﻿using MechAddin.Common;
using System.Collections.Generic;

namespace MechAddin.Command.移动零件
{
    class 移动零件ViewModel : ViewModelBase
    {
        private string dis;
        public string Dis
        {
            get => dis;
            set { dis = value; OnPropertyChanged(); } 

        }
        private bool skipFirst;
        public bool SkitFirst
        {
            get => skipFirst;
            set { skipFirst = value; OnPropertyChanged(); }
        }
        public bool copy;
        public bool Copy
        {
            get => copy;
            set { copy = value; OnPropertyChanged(); }
        }
        public void Run()
        {
            移动零件Model model = new 移动零件Model();
            if (copy)
            {
                string[] strings = dis.Split('+');
                List<double> values = new List<double>();
                double x = 0;
                foreach (string s in strings)
                {
                    double v = s.Parse();
                    if (v != 0)
                    {
                        values.Add(v + x);
                        x += v;
                    }
                }
                if (values.Count > 0)
                {
                    model.复制移动零件(values, SkitFirst);
                }
            }
            else
            {
                string[] strings = dis.Split('+');
                double x = 0;
                foreach (string s in strings)
                {
                    x += s.Parse();
                }
                model.移动零件(x, SkitFirst);
            }
        }
    }
}
